﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL;
using GCELibrary.Current;
namespace ZF.WS.fz
{
    public partial class life :BLL.Page.PageBase
    {
        public IMember CMember { get { return SiteInfo.GetCurrentMember(); } }

        [PageArgument(Key = "id",CanNull=false)]
        public int Id { get; set; }
        public Model.G_Buddha Buddha { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
 
            using (var dc = SiteInfo.CreateDBDataContext())
            {
                Buddha = dc.G_Buddha.FirstOrDefault(p => p.BuddhaId == Id);
                if (Buddha == null)
                {
                    throw WarnFactory.CreateWarn(WarnCode.ReocrdNoFind);
                }

                var list=dc.G_Offering.ToList();
                var dic = list.GroupBy(p=>p.Group).ToDictionary(p => p.Key);

                this.lvGPTitle.DataSource = dic;
                this.lvGPTitle.DataBind();

                var xylist = dc.G_Wishing.Where(p => p.BuddhaId == Buddha.BuddhaId)
                .Join(dc.US_Member, p => p.MemberId, m => m.MemberId, (p, m) => new
                {
                    Wishing = p,
                    Name = m.Account,
                    Msg = p.Content,
                }).OrderByDescending(p => p.Wishing.WishingId).Take(10).ToList();
                this.lvXY.DataSource = xylist;
                this.lvXY.DataBind();



                this.ddlFZ.DataSource = dc.G_Buddha.ToList().Select(p => new
                {
                     Key=p.BuddhaId,
                     Text=p.Name,
                });
                this.ddlFZ.DataBind();
                this.ddlFZ.SelectedValue = this.Id.ToString();
            }
            
        }
    }
}
